package edu.gatech.asthma.ui_support.login;

import edu.gatech.asthma.R;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Fragment for the profile picture selection page
 */
public class ProfilePicPageFragment extends Fragment{

    /** Constructs a new profile page fragment.
     *  trick: Create fragment using static method and use bundle to pass information
     *  @param name Text to display with image
     *  @param image The resource id of the image. Profile images must be stored in the resource folder (not in db)
     */
    public static Fragment newInstance(String name, int imageTint, int imageAccent, int imageTop, int colorTint, int colorAccent) {
    	ProfilePicPageFragment fragment = new ProfilePicPageFragment();
        Bundle args = new Bundle(2);
        args.putString("NAME", name);
        args.putInt("IMG_TINT", imageTint);
        args.putInt("IMG_ACCENT", imageAccent);
        args.putInt("IMG_TOP", imageTop);
        args.putInt("COLOR_TINT", colorTint);
        args.putInt("COLOR_ACCENT", colorAccent);
        fragment.setArguments(args);
        return fragment;
    }
    
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    	String name = getArguments().getString("NAME");
    	int imageTintId = getArguments().getInt("IMG_TINT");
    	int imageAccentId = getArguments().getInt("IMG_ACCENT");
    	int imageTopId = getArguments().getInt("IMG_TOP");
    	int colorTintId = getArguments().getInt("COLOR_TINT");
    	int colorAccentId = getArguments().getInt("COLOR_ACCENT");
    	
        // Inflate the layout for the profile name and image.
        View view = inflater.inflate(R.layout.profile_pic_page, container, false);
        //Set the name
        TextView nameText = (TextView)view.findViewById(R.id.profile_name);
        nameText.setText(name);
        
        //Set the image and tint the layers according to user preferences
        ImageView imgTint = (ImageView)view.findViewById(R.id.profile_img_tint);
        imgTint.setImageResource(imageTintId);
        imgTint.setColorFilter(getResources().getColor(colorTintId));
        
        ImageView imgAccent = (ImageView)view.findViewById(R.id.profile_img_accent);
        imgAccent.setImageResource(imageAccentId);
        imgAccent.setColorFilter(getResources().getColor(colorAccentId));
        
        ImageView imgTop = (ImageView)view.findViewById(R.id.profile_img_top);
        imgTop.setImageResource(imageTopId);
    	return view;
    }
}
